#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void Swap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void BubbleSort(int* a,int n)
{
	int j = 0;
	for (j = 0; j < n; ++j)
	{
		int exchange = 0;
		for (int i = 1; i < j; i++)
		{
			if (a[i - 1] > a[i])
			{
				Swap(&a[i-1],&a[i]);
				exchange = 1;
			}
		}
		if (exchange == 0)
		{
			break;
		}
	}
}
TestOP()
{
	srand(time(0));
	const int N = 10000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	if (a1 == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}
	/*int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);*/
	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand();
		/*a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];*/

	}
	int begin1 = clock();
	BubbleSort(a1,N);
	int end1 = clock();

	printf("BubbleSort:%d\n", end1 - begin1);
	free(a1);


}

int main()
{
	TestOP();
	return 0;
}